home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 626-637 / disk_633 / galer / source / galasm.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  29KB  |  1,144 lines

  1. /****************************************************************/
  2. /*                                */
  3. /* GALAsm.c - enthält GAL-Assembler                */
  4. /*                                */
  5. /* compilieren: cc GALAsm.c                    */
  6. /*                                */
  7. /****************************************************************/
  8.  
  9.  
  10.  
  11. #include "exec/types.h"
  12. #include "exec/memory.h"
  13. #include <ctype.h>
  14. #include <stdio.h>
  15. #include <functions.h>
  16. #include "GALer.h"
  17.  
  18.  
  19.  
  20. extern    int    linenum, MaxFuseAdr;
  21. extern    int    GenJedec, GenFuse, GenChip, GenPin;
  22. extern    UBYTE    *actptr, *buffend, GadgetSBuff[60];
  23.  
  24. extern    struct    JedecStruct    Jedec;
  25.  
  26.  
  27. struct    Pin        actPin;
  28. struct    GAL_OLMC    OLMC[8];
  29.  
  30.  
  31.             /*Diese Arrays geben an in welche Spalte der ent- */
  32.             /*sprechende Pin eingekoppelt (bzw. rückgekoppelt)*/
  33.             /*wird. Für die invertierende Einkopplung ist 1 zu*/
  34.             /*addieren, um die entsprechende Spalte zu erhalten*/
  35.             /* -1: keine Einkopplung auf Fuse-Matrix vorhanden */
  36.             /*GAL16V8:*/
  37. int    PinToFuse16Mode1[20]    = {  2, 0, 4, 8,12,16,20,24,28,-1,
  38.                     30,26,22,18,-1,-1,14,10, 6,-1 };
  39. int    PinToFuse16Mode2[20]    = {  2, 0, 4, 8,12,16,20,24,28,-1,
  40.                     30,-1,26,22,18,14,10, 6,-1,-1 };
  41. int    PinToFuse16Mode3[20]    = { -1, 0, 4, 8,12,16,20,24,28,-1,
  42.                     -1,30,26,22,18,14,10, 6, 2,-1 };
  43.  
  44.             /*GAL20V8:*/
  45. int    PinToFuse20Mode1[24]    = {  2, 0, 4, 8,12,16,20,24,28,32,36,-1,
  46.                     38,34,30,26,22,-1,-1,18,14,10, 6,-1 };
  47. int    PinToFuse20Mode2[24]    = {  2, 0, 4, 8,12,16,20,24,28,32,36,-1,
  48.                     38,34,-1,30,26,22,18,14,10,-1, 6,-1 };
  49. int    PinToFuse20Mode3[24]    = { -1, 0, 4, 8,12,16,20,24,28,32,36,-1,
  50.                     -1,38,34,30,26,22,18,14,10, 6, 2,-1 };
  51.  
  52.             /*dieses Array gibt an in welcher Zeile der*/
  53.             /*erste Eingang der OLMC-Zelle liegt*/
  54. int    ToOLMC[8]        = { 56,48,40,32,24,16, 8, 0 };
  55.  
  56.  
  57.  
  58. UBYTE    PinNames[24][10];
  59. UBYTE    ModeErrorStr[] = {"Modus x:  Pin xx"};
  60.  
  61.  
  62.  
  63. LONG    fsize;
  64. UBYTE    *fbuff;
  65.  
  66. int    num_of_pins, num_of_col, modus, gal_type;
  67. int    pinnameflag = 0;
  68.  
  69.  
  70. /* AssembleInputFile:
  71.    Eingabe-Datei assemblieren
  72.    Aufruf: AssembleInputFile();
  73. */
  74. AssembleInputFile()
  75. {
  76. UBYTE    chr, filenamebuff[64];
  77. UBYTE    *bool_start;
  78. char    prevOp;
  79. int    i, j, k, l, n, m;
  80. int    oldMaxFuseAdr, max_chr;
  81. int    pass, pin_num, bool_linenum;
  82. int    actOLMC, row_offset;
  83.  
  84.  
  85.  if (MyRequest(LOAD_REQ,(UBYTE *)"Bitte Namen des Source-Files eingeben")) {
  86.    strcpy(&filenamebuff,&GadgetSBuff);        /*.pld an Dateinamen anfügen*/
  87.    strcat(&filenamebuff,(UBYTE *)".pld");
  88.  
  89.    fsize=FileSize(&filenamebuff);
  90.    switch (fsize) {
  91.      case -1L: {
  92.        ErrorReq(1);
  93.        return(-1);
  94.        break;
  95.       }
  96.      case -2L: {
  97.        ErrorReq(2);
  98.        return(-2);
  99.        break;
  100.       }
  101.      case 0L: {
  102.        ErrorReq(4);
  103.        return(-4);
  104.        break;
  105.       }
  106.     }
  107.    if ((fbuff=(UBYTE *)AllocMem(fsize,MEMF_PUBLIC))) {
  108.      if ((ReadFile(&filenamebuff,fsize,fbuff))) {
  109.        PrintText((UBYTE *)"Datei ist geladen");
  110.  
  111.  
  112.        actptr  = fbuff;
  113.        buffend = fbuff+fsize;
  114.        linenum = 1;
  115.  
  116.        for (n=0; n<sizeof(Jedec); n++) {    /*Jedec-Sruktur zurücksetzen*/
  117.      if (n < LOGIC20_SIZE)
  118.        Jedec.GALLogic[n] = 1;        /*Fuse-Matrix auf 1*/
  119.      else
  120.        Jedec.GALLogic[n] = 0;        /*ACW, PT usw. auf 0*/
  121.     }
  122.  
  123.        for (n=0; n<8; n++) {            /*OLMC-Sruktur auf 0 setzen*/
  124.      OLMC[n].Active  = 0;
  125.      OLMC[n].PinType = 0;
  126.      OLMC[n].TriCon  = 0;
  127.      OLMC[n].LineNum = 0;
  128.     }
  129.                     /*GAL-Typ feststellen*/
  130.        if (!strncmp(actptr,(UBYTE *)"GAL16V8",7)) {
  131.      num_of_pins = 20;            /*Anzahl der Pins   */
  132.      num_of_col  = MAX_FUSE_ADR16 + 1;    /*Anzahl der Spalten*/
  133.      gal_type    = GAL16V8;
  134.         }
  135.        else
  136.          if (!strncmp(actptr,(UBYTE *)"GAL20V8",7)) {
  137.        num_of_pins = 24;            /*Anzahl der Pins   */
  138.        num_of_col  = MAX_FUSE_ADR20 + 1;    /*Anzahl der Spalten*/
  139.        gal_type    = GAL20V8;
  140.       }
  141.      else {
  142.        AsmError(1);
  143.        return(-1);
  144.       }
  145.  
  146.                     /*Signatur (8 Bytes der 2.Zeile) in Puffer schreiben*/
  147.        if (GetNextLine()) {            /*Datei-Ende erreicht?*/
  148.      AsmError(2);                /*ja, dann Fehler*/
  149.      return(-1);
  150.     }
  151.        n = m = 0;
  152.        while((*actptr!=0x0A) && (n<8)) {    /*Signatur in Jedec-Stuktur schreiben*/
  153.      chr = *actptr;
  154.      for (m=0; m<8; m++) {
  155.        Jedec.GALSig[n*8+m] = (chr>>(7-m)) & 0x1; 
  156.       }
  157.      actptr++;
  158.      n++;
  159.      if (actptr>buffend) {            /*Fileende erreicht ?*/
  160.        AsmError(2);                /*ja, dann Fehler*/
  161.        return(-1);
  162.       }
  163.     } 
  164.  
  165.                     /*Pin-Namen in "PinNames" eintragen*/
  166.        pinnameflag = 0;                    /*Pinnamen ungültig*/
  167.        GetNextLine();
  168.        for (n=0; n<num_of_pins; n++) {
  169.       if (GetNextChar(FALSE)) {            /*Dateiende?*/
  170.         AsmError(2);                /*ja, dann Fehler*/
  171.         return(-1);
  172.        }
  173.       m = 0;
  174.       chr = *actptr;
  175.       if (chr == '/')
  176.         max_chr = 10;
  177.       else
  178.         max_chr = 9;
  179.       if (!(isalpha(chr) || isdigit(chr) || chr=='/')) {
  180.         AsmError(5);
  181.         return(-1);
  182.        }
  183.       k = 0;
  184.       while (isalpha(chr) || isdigit(chr) || chr=='/') {
  185.          if ((chr == '/') && (k != 0)) {    /* '/' nicht am Anfang des Pinnamens?*/
  186.            AsmError(10);
  187.            return(-1);
  188.           }
  189.          k = 1;
  190.          actptr++;
  191.          if ((chr=='/') && (!(isalpha(*actptr) || isdigit(*actptr)))) {
  192.            AsmError(3);
  193.            return(-1);
  194.           }
  195.          PinNames[n][m] = chr;
  196.          m++;
  197.          chr = *actptr;
  198.          if (m == max_chr) {        /*zuviele Buchstaben?*/
  199.            AsmError(4);
  200.            return(-1);
  201.           }
  202.         }
  203.       PinNames[n][m] = 0;            /*Stringende kennzeichnen*/
  204.  
  205.       for (l=0; l<n; l++) {            /*Pinname doppelt?*/
  206.         if (strcmp(&PinNames[l],(UBYTE *)"NC")) {
  207.           i = j = 0;
  208.           if (PinNames[l][0] == '/') i = 1;
  209.           if (PinNames[n][0] == '/') j = 1;
  210.           if (!strcmp(&PinNames[l][i],&PinNames[n][j])) {
  211.         AsmError(9);
  212.         return(-1);
  213.            }
  214.          }
  215.        }
  216.                         /*GND an entsprechenden Pin?*/
  217.       if (!strcmp(&PinNames[n][0],(UBYTE *)"GND")) {
  218.         if (n+1 != num_of_pins/2) {
  219.           AsmError(6);
  220.           return(-1);
  221.          }
  222.        }
  223.       if (n+1 == num_of_pins/2) {
  224.         if (strcmp(&PinNames[n][0],(UBYTE *)"GND")) {
  225.           AsmError(8);
  226.           return(-1);
  227.          }
  228.        }
  229.                         /*VCC an entsprechenden Pin?*/
  230.       if (!strcmp(&PinNames[n][0],(UBYTE *)"VCC")) {
  231.         if (n+1 != num_of_pins) {
  232.           AsmError(6);
  233.           return(-1);
  234.          }
  235.        }
  236.       if (n+1 == num_of_pins) {
  237.         if (strcmp(&PinNames[n][0],(UBYTE *)"VCC")) {
  238.           AsmError(7);
  239.           return(-1);
  240.          }
  241.        }
  242.     }
  243. /* Boolean-Equations auswerten:
  244.    Dabei werden die Boolean-Equations zweimal untersucht. Beim ersten
  245.    Durchlauf werden die OLMC-Pins ausgewertet und die OLMC-Struktur ge-
  246.    füllt. Mit Hilfe dieser Struktur läßt sich auf den notwendigen Modus
  247.    (1, 2 oder 3) schließen. Beim zweiten Durchlauf wird dann die
  248.    Fuse-Matrix erstellt.
  249.  */
  250.  
  251.        if (GetNextChar(FALSE)) {        /*Dateiende?*/
  252.      AsmError(2);                /*ja, dann Fehler*/
  253.      return(-1);
  254.     }
  255.  
  256.        bool_start   = actptr;            /*Zeiger auf Anfang der Equations*/
  257.        bool_linenum = linenum;            /*Zeilennummer merken*/
  258.  
  259.        for (pass=0; pass<2; pass++) {        /*2 Durchläufe*/
  260.      if (pass) {            /*2. Durchlauf?->ACW erstellen*/
  261.        modus = 0;            /*und Modus bestimmen*/
  262.        for (n=0; n<8; n++) {        /*alle OLMCs untersuchen*/
  263.          if (OLMC[n].PinType == REGOUT) {    /*OLMC als Reg. vorhanden?*/
  264.            modus = MODE3;            /*ja, dann MUß Mode3 vorliegen*/
  265.            Jedec.GALSYN = 0;        /*SYN- und AC0-Bit setzen*/
  266.            Jedec.GALAC0 = 1;
  267.            break;
  268.           }
  269.         }
  270.  
  271.        if (!modus) {
  272.          for (n=0; n<8; n++) {
  273.            if (OLMC[n].PinType == TRIOUT) {    /*OLMC als Tri. vorhanden?*/
  274.              modus = MODE2;            /*ja, dann Mode2*/
  275.              Jedec.GALSYN = 1;        /*SYN- und AC0-Bit setzen*/
  276.              Jedec.GALAC0 = 1;
  277.          break;
  278.             }
  279.           }
  280.         }
  281.  
  282.        if (!modus) {
  283.          modus = MODE1;            /*noch kein Mode? dann Mode1*/
  284.          Jedec.GALSYN = 1;            /*SYN- und AC0-Bit setzen*/
  285.          Jedec.GALAC0 = 0;
  286.         }
  287.                     /*falls Modus 1 voliegt alle*/
  288.                     /*Ausgänge deren Typ nicht an-*/
  289.                     /*gegeben wurde in komb. Ausgänge*/
  290.                     /*umwandeln*/
  291.                     /*falls Modus 2 oder 3 vorliegt*/
  292.                     /*alle Ausgänge deren Typ nicht an-*/
  293.                     /*gegeben wurde in Tristate mit per-*/
  294.        for (n=0; n<8; n++) {    /*manenter Freischaltung umwandeln*/
  295.          if (OLMC[n].PinType == COM_TRI_OUT) {
  296.            if (modus == MODE1) {
  297.          OLMC[n].PinType = COMOUT;
  298.         }
  299.            else {
  300.              OLMC[n].PinType = TRIOUT;
  301.              OLMC[n].TriCon  = TRI_VCC;
  302.         }
  303.           }
  304.         }
  305.                     /*überprüfen ob Verstöße gegen den*/
  306.                     /*ermittelten Modus vorliegen*/
  307.        if (modus == MODE1) {
  308.          for (n=0; n<8; n++) {
  309.            if (OLMC[n].PinType == INPUT) {
  310.              if (gal_type == GAL16V8) {
  311.            pin_num = n + 12;
  312.                if ((pin_num == 15) || (pin_num == 16)) {
  313.              linenum = OLMC[n].LineNum;
  314.              AsmError(18);
  315.              return(-1);
  316.                 }
  317.               }
  318.              if (gal_type == GAL20V8) {
  319.            pin_num = n + 15;
  320.                if ((pin_num == 18) || (pin_num == 19)) {
  321.              linenum = OLMC[n].LineNum;
  322.              AsmError(19);
  323.              return(-1);
  324.                 }
  325.               }
  326.             }
  327.           }
  328.         }
  329.  
  330.        if (modus == MODE2) {
  331.          for (n=0; n<8; n++) {
  332.            if (OLMC[n].PinType == INPUT) {
  333.              if (gal_type == GAL16V8) {
  334.            pin_num = n + 12;
  335.                if ((pin_num == 12) || (pin_num == 19)) {
  336.              linenum = OLMC[n].LineNum;
  337.              AsmError(20);
  338.              return(-1);
  339.                 }
  340.               }
  341.              if (gal_type == GAL20V8) {
  342.            pin_num = n + 15;
  343.                if ((pin_num == 15) || (pin_num == 22)) {
  344.              linenum = OLMC[n].LineNum;
  345.              AsmError(21);
  346.              return(-1);
  347.                 }
  348.               }
  349.             }
  350.           }
  351.         }
  352.                     /*ACW erstellen: SYN und AC0 sind*/
  353.                     /*bereits festgelegt*/
  354.        for (n=0; n<PT_SIZE; n++)        /*Produkftermfreigabe auf 1*/
  355.          Jedec.GALPT[n] = 1;
  356.  
  357.                     /*AC1-Bits bestimmen*/
  358.        for (n=0; n<AC1_SIZE; n++) {
  359.          if ((OLMC[n].PinType == INPUT) || (OLMC[n].PinType == TRIOUT))
  360.            Jedec.GALAC1[AC1_SIZE-1-n] = 1;
  361.         }
  362.  
  363.        for (n=0; n<XOR_SIZE; n++) {        /*XOR-Bits bestimmen*/
  364.          if (((OLMC[n].PinType == COMOUT) ||
  365.           (OLMC[n].PinType == TRIOUT) ||
  366.           (OLMC[n].PinType == REGOUT)) &&
  367.           (OLMC[n].Active  == ACTIVE_HIGH))
  368.            Jedec.GALXOR[XOR_SIZE-1-n] = 1;
  369.         }
  370.  
  371.       }
  372.  
  373.  
  374.      actptr  = bool_start;
  375.      linenum = bool_linenum;
  376.          goto label1;
  377.  
  378. loop1:     if (GetNextChar(FALSE)) {            /*Dateiende?*/
  379.        AsmError(2);                    /*ja, dann Fehler*/
  380.        return(-1);
  381.       }
  382.      chr = 0x00;
  383.      if (*actptr == '.') {
  384.        actptr++;
  385.        chr = *actptr;
  386.        if (!((chr == 'T') || (chr == 'E') || (chr == 'R'))) {
  387.          AsmError(13);
  388.          return(-1);
  389.         }         
  390.        actptr++;
  391.        if (GetNextChar(FALSE)) {            /*Dateiende?*/
  392.          AsmError(2);                /*ja, dann Fehler*/
  393.          return(-1);
  394.         }
  395.       }
  396.  
  397.      actOLMC = (int)actPin.p_Pin;        /*OLMC-Offset merken*/
  398.      if (gal_type == GAL16V8)
  399.        actOLMC -= 12;
  400.      else
  401.        actOLMC -= 15;
  402.      row_offset  = 0;            /*Offset für OR am OLMC*/
  403.      prevOp         = 0;            /*vorherige Verknüpfung*/
  404.                         /*chr enthält T,R,E oder 0x00*/
  405.      if (!pass) {                /*Pass 1?*/
  406.        if ( ((gal_type == GAL16V8)        /*OLMC-Pin?*/
  407.          && (actPin.p_Pin >= 12) && (actPin.p_Pin <= 19)) ||
  408.         ((gal_type == GAL20V8)
  409.          && (actPin.p_Pin >= 15) && (actPin.p_Pin <= 22)) ) {
  410.          if (gal_type == GAL16V8)
  411.            n=actPin.p_Pin-12;
  412.          if (gal_type == GAL20V8)
  413.            n=actPin.p_Pin-15;
  414.          if (chr != 'E') {            /*keine Tristate-Freigabe?*/
  415.                         /*mehrfache Zuweisung?*/
  416.            if ((!OLMC[n].PinType) || (OLMC[n].PinType == INPUT)) {
  417.          if (actPin.p_Neg)
  418.            OLMC[n].Active = ACTIVE_LOW;
  419.          else
  420.            OLMC[n].Active = ACTIVE_HIGH;
  421.  
  422.          switch (chr) {
  423.            case 'T': { OLMC[n].PinType = TRIOUT;
  424.                    break;
  425.                  }
  426.            case 'R': { OLMC[n].PinType = REGOUT;
  427.                    break;
  428.                  }
  429.            case 0x00:{ OLMC[n].PinType = COM_TRI_OUT;
  430.                    break;
  431.                  }
  432.           }
  433.         }
  434.            else {
  435.          AsmError(16);
  436.          return(-1);
  437.         }
  438.           }
  439.          else {
  440.            if (OLMC[n].PinType == TRIOUT) {
  441.          if (actPin.p_Neg) {        /*kein '/' bei Tri.-Kontr.!*/
  442.            AsmError(32);
  443.            return(-1);
  444.           }
  445.          if (OLMC[n].TriCon) {        /*Tri.-Kontrolle doppelt?*/
  446.            AsmError(22);
  447.            return(-1);
  448.           }
  449.          OLMC[n].TriCon = TRICON;    /*Tri.-Kontrolle angegeben*/
  450.         }
  451.            if ((!OLMC[n].PinType) || (OLMC[n].PinType == INPUT)) {
  452.          AsmError(17);            /*zuerst Tri.Kon.?*/
  453.          return(-1);            /*dann Fehler*/
  454.         }
  455.            if (OLMC[n].PinType == REGOUT) { /*Register? dann Fehler*/
  456.          AsmError(23);
  457.          return(-1);
  458.         }
  459.            if (OLMC[n].PinType == COM_TRI_OUT) { /*kein klares .T?*/
  460.          AsmError(24);
  461.          return(-1);
  462.         }
  463.           }
  464.         }
  465.        else {
  466.          AsmError(15);
  467.          return(-1);
  468.         }
  469.       }
  470.  
  471.  
  472.  
  473.      if (*actptr != '=') {                /* '=' ?*/
  474.        AsmError(14);                /*nein, dann Fehler*/
  475.        return(-1);
  476.       }         
  477. loop2:
  478.      actptr++;
  479.      if (GetNextChar(FALSE)) {            /*Dateiende?*/
  480.        AsmError(2);                    /*ja, dann Fehler*/
  481.        return(-1);
  482.           }
  483.      IsPinName();
  484.      if (!actPin.p_Pin) {                /*Pinname?*/
  485.        AsmError(11);                /*nein, dann Fehler*/
  486.        return(-1);
  487.       }
  488.      if (actPin.p_Pin==NC_PIN) {            /*NC als Pinname?*/
  489.        AsmError(12);                /*ja, dann Fehler*/
  490.        return(-1);
  491.       }
  492.      if (GetNextChar(FALSE)) {            /*Dateiende?*/
  493.        AsmError(2);                    /*ja, dann Fehler*/
  494.        return(-1);
  495.       }
  496.                             /*kein Vcc/GND in den*/
  497.                             /*Boolean-Gleichungen*/
  498.      if ((actPin.p_Pin == num_of_pins) || (actPin.p_Pin == num_of_pins/2)) {
  499.        if (chr != 'E') {
  500.          AsmError(25);                /*Vcc/GND dann Fehler*/
  501.          return(-1);
  502.         }
  503.       }
  504.  
  505.  
  506.  
  507.      if (!pass) {                    /*Pass 1?*/
  508.        if ( ((gal_type == GAL16V8)            /*OLMC-Pin?*/
  509.          && (actPin.p_Pin >= 12) && (actPin.p_Pin <= 19)) ||
  510.         ((gal_type == GAL20V8)
  511.          && (actPin.p_Pin >= 15) && (actPin.p_Pin <= 22)) ) {
  512.          if (gal_type == GAL16V8)
  513.            n=actPin.p_Pin-12;
  514.          if (gal_type == GAL20V8)
  515.            n=actPin.p_Pin-15;
  516.          if (!OLMC[n].PinType) {            /*OLMC bereits def.?*/
  517.            OLMC[n].PinType = INPUT;            /*nein, dann Eingang*/
  518.            OLMC[n].LineNum  = linenum;        /*Zeile merken*/
  519.           }
  520.         }
  521.       }
  522.                     /*im 2.Durchlauf Fuse-Matrix*/
  523.                     /*erstellen; chr = T,R,E oder 0x00*/
  524.      if (pass) {
  525.        if (chr != 'E') {
  526.          if (!row_offset) {            /*Zeilenoffset noch 0?*/
  527.            if ( (modus != MODE1) && (OLMC[actOLMC].PinType != REGOUT)) {
  528.              row_offset = 1;
  529.             }
  530.           }
  531.         }
  532.                     /*auf Verstoß gegen Modus prüfen*/
  533.        pin_num = actPin.p_Pin;
  534.        if (modus == MODE1) {        /*Verstoß gegen Mode 1?*/
  535.          if ((gal_type==GAL16V8) && ((pin_num==15) || (pin_num==16))) {
  536.            AsmError(18);
  537.            return(-1);
  538.           }
  539.          if ((gal_type==GAL20V8) && ((pin_num==18) || (pin_num==19))) {
  540.            AsmError(19);
  541.            return(-1);
  542.           }
  543.         }
  544.        if (modus == MODE2) {        /*Verstoß gegen Mode 2?*/
  545.          if ((gal_type==GAL16V8) && ((pin_num==12) || (pin_num==19))) {
  546.            AsmError(20);
  547.            return(-1);
  548.           }
  549.          if ((gal_type==GAL20V8) && ((pin_num==15) || (pin_num==22))) {
  550.            AsmError(21);
  551.            return(-1);
  552.           }
  553.         }
  554.        if (modus == MODE3) {        /*Verstoß gegen Mode 3?*/
  555.          if ((gal_type==GAL16V8) && ((pin_num==1) || (pin_num==11))) {
  556.            AsmError(26);
  557.            return(-1);
  558.           }
  559.          if ((gal_type==GAL20V8) && ((pin_num==1) || (pin_num==13))) {
  560.            AsmError(27);
  561.            return(-1);
  562.           }
  563.         }
  564.                     /*wenn Tristate-Kontrolle und GND*/
  565.                     /*dann Fuse-Zeile auf 0 setzen   */
  566.        if (chr == 'E') {
  567.  
  568.          if (prevOp == '+') {        /*max. 1 Produktterm*/
  569.            AsmError(29);            /*mehr, dann Fehler*/
  570.            return(-1);
  571.           }
  572.          if ((pin_num == num_of_pins) || (pin_num == num_of_pins/2)) {
  573.            if (!prevOp && (*actptr != '*' ) && (*actptr != '+')) {
  574.          if (pin_num == num_of_pins/2) {
  575.            m = ToOLMC[actOLMC] * num_of_col;
  576.            for (n=m; n<m+num_of_col; n++)
  577.              Jedec.GALLogic[n] = 0;
  578.           }
  579.             }
  580.            else {
  581.              AsmError(28);
  582.              return(-1);
  583.             }
  584.           }
  585.          else {                /*UND-Verknüpfung erstellen*/
  586.            SetAND(ToOLMC[actOLMC], pin_num, actPin.p_Neg);
  587.           }
  588.         }
  589.        else {
  590.          if (prevOp == '+') {        /*ODER-Verknüpfung?*/
  591.            row_offset++;            /*ja, dann nächste Zeile*/
  592.            if (row_offset == MAX_OR) {    /*zuviele Produktterme?*/
  593.          if ((modus != MODE1) && (OLMC[actOLMC].PinType != REGOUT)) {
  594.            AsmError(31);
  595.            return(-1);
  596.           }
  597.          else {
  598.            AsmError(30);
  599.            return(-1);
  600.           }
  601.         }
  602.           }                    /*UND-Verknüpfung setzen*/
  603.          SetAND(ToOLMC[actOLMC]+row_offset, pin_num, actPin.p_Neg);
  604.         }
  605.                         /*kommt noch eine Verknüpfung?*/
  606.        if ((*actptr != '+') && (*actptr != '*') && (chr != 'E')) { /*nein*/
  607.          row_offset++;                /*Rest der OLMC- */
  608.          if (row_offset != MAX_OR) {        /*Zeilen auf 0    */
  609.            m = (ToOLMC[actOLMC] + row_offset) * num_of_col;
  610.            for (n=m; n<m+(MAX_OR-row_offset) * num_of_col; n++)
  611.          Jedec.GALLogic[n] = 0;
  612.           }
  613.         }
  614.       }
  615.  
  616.  
  617.      if ((*actptr == '+') || (*actptr == '*')) {
  618.        prevOp = *actptr;
  619.        goto loop2;
  620.       }
  621.  
  622.  
  623.      if (strncmp(actptr,(UBYTE *)"DESCRIPTION",11)) {
  624. label1:       IsPinName();
  625.        if (!actPin.p_Pin) {                /*Pinname?*/
  626.          AsmError(11);                /*nein, dann Fehler*/
  627.          return(-1);
  628.         }
  629.        if (actPin.p_Pin==NC_PIN) {            /*NC als Pinname?*/
  630.          AsmError(12);                /*ja, dann Fehler*/
  631.          return(-1);
  632.         }
  633.        goto loop1;
  634.       }
  635.  
  636.     }
  637.                     /*Fuse-Matrix der nichtverwendeten*/
  638.                     /*OLMCs und der OLMCs die als Eingang*/
  639.                     /*programmiert sind auf 0 setzen*/
  640.        for (n=0; n<8; n++) {
  641.      if ((OLMC[n].PinType == NOTUSED) || (OLMC[n].PinType == INPUT)) {
  642.        l = ToOLMC[n];
  643.        l = l * num_of_col;
  644.        m = l + 8 * num_of_col;
  645.        for (k=l; k<m; k++)
  646.         Jedec.GALLogic[k] = 0;
  647.       }
  648.     }
  649.                     /*Jedec-Struktur ist fertig (jubel)*/
  650.  
  651.        pinnameflag = 1;            /*Pinnamen sind gültig*/
  652.  
  653.        FreeMem(fbuff, fsize);        /*Puffer für File .pld*/
  654.  
  655.                     /* angewählte Files erstellen*/
  656.        if (GenJedec==YES) {
  657.          if (MyRequest(SAVE_REQ,(UBYTE *)"Bitte Namen für Jedec-Datei eingeben")) {
  658.        oldMaxFuseAdr = MaxFuseAdr;
  659.        if (gal_type == GAL16V8) 
  660.          MaxFuseAdr = MAX_FUSE_ADR16;
  661.        else
  662.          MaxFuseAdr = MAX_FUSE_ADR20;
  663.        WriteJedecFile();
  664.        MaxFuseAdr = oldMaxFuseAdr;
  665.       }
  666.     }
  667.        if (GenFuse==YES)
  668.      WriteFuseFile(); 
  669.        if (GenChip==YES)
  670.       WriteChipFile();
  671.        if (GenPin==YES)
  672.      WritePinFile();
  673.        return(0);                /*kein Fehler aufgetreten*/
  674.       }
  675.      else {
  676.        ErrorReq(3);                /*Lesefehler*/
  677.        FreeMem(fbuff,fsize);
  678.        return(-2);
  679.       }
  680.     }
  681.    else {
  682.      ErrorReq(2);                /*kein Speicher*/
  683.      return(-2);
  684.     }
  685.   }
  686. }
  687.  
  688.  
  689.  
  690.  
  691.  
  692. /* setze eine UND-Verknüpfung (=0) in der Fuse-Matrix
  693.    row     :  Zeile in der die UND-Verknüpfung entstehen soll
  694.    pinnum  :  Pin der UND-verknüpft werden soll
  695.    negation:  0: Pin nicht negiert; 1: Pin negiert ('/')
  696. */
  697. SetAND(row, pinnum, negation)
  698. int    row, pinnum, negation;
  699. {
  700. int column;
  701.  
  702.  if (gal_type == GAL16V8) {
  703.    if (modus == MODE1)
  704.      column = PinToFuse16Mode1[pinnum - 1];
  705.    if (modus == MODE2)
  706.      column = PinToFuse16Mode2[pinnum - 1];
  707.    if (modus == MODE3)
  708.      column = PinToFuse16Mode3[pinnum - 1];
  709.   }
  710.  else {
  711.    if (modus == MODE1)
  712.      column  =  PinToFuse20Mode1[pinnum - 1];
  713.    if (modus == MODE2)
  714.      column  =  PinToFuse20Mode2[pinnum - 1];
  715.    if (modus == MODE3)
  716.      column  =  PinToFuse20Mode3[pinnum - 1];
  717.   }
  718.  Jedec.GALLogic[row * num_of_col + column + negation] = 0;
  719. }
  720.  
  721.  
  722.  
  723.  
  724. /* Überprüfe ob bei "actptr" ein Pinname steht der in "PinNames" eingetragen
  725.    ist und der kein NC (not connected) ist.
  726.    "actptr" wird auf erstes Zeichen hinter den Pinnamen gestellt
  727.    actPin.p_Pin: Pinnummer oder NC_PIN; 0: kein Pinname
  728.    actPin.p_Neg: bei active low = 0; bei active high = 1
  729. */
  730. IsPinName()
  731. {
  732. int    i, k, n;
  733. UBYTE    *oldactptr;
  734.  
  735.  actPin.p_Neg = 0;        /*Pin-Struktur zurücksetzen*/
  736.  actPin.p_Pin = 0;
  737.  
  738.  if (*actptr == '/' ) {        /*Negation?*/
  739.    actptr++;
  740.    actPin.p_Neg = 1;
  741.   }
  742.  
  743.  n = 0;                /*Länge des möglichen Pinnamens ermitteln*/
  744.  oldactptr = actptr;
  745.  while (isalpha(*actptr) || isdigit(*actptr)) {
  746.    actptr++;
  747.    n++;
  748.   }
  749.  
  750.  if (n)
  751.    if ((n == 2 ) && !strncmp(oldactptr,(UBYTE *)"NC",2))  /*NC ?*/
  752.      actPin.p_Pin = NC_PIN;                /*ja, dann NC-Pin*/
  753.    else
  754.      for (k=0; k<num_of_pins; k++) {     /*List der Pinnamen durchsuchen*/
  755.        i = 0;
  756.        if (PinNames[k][0] == '/')
  757.          i = 1;
  758.        if (n == strlen(&PinNames[k][i]))    /*Stringlängen gleich?*/       
  759.          if (!(strncmp(oldactptr,&PinNames[k][i],n))) {     /*ja, dann Strings*/
  760.        actPin.p_Pin = k+1;                 /*vergeichen      */
  761.        break;
  762.           }
  763.       }
  764. }
  765.  
  766.  
  767.  
  768.  
  769. /*suche ab "actptr" das nächste Zeichen das kein Space, TAB, LF ist
  770.   Aufruf:   linefeed=TRUE: return auch bei 0x0A, FALSE: kein return bei 0x0A
  771.   Ergebins: 0:Zeichen gefunden, actptr=Zeiger auf dieses Zeichen
  772.         1:kein Zeichen mehr da
  773. */
  774. GetNextChar(linefeed)
  775. int    linefeed;
  776. {
  777.  for(;;) {
  778.    switch (*actptr) {
  779.      case 0x0A: {                /*LineFeed*/
  780.        actptr++;
  781.        linenum++;
  782.        if (linefeed==TRUE) return(0);
  783.        break;
  784.       }
  785.      case  ' ':                    /*Space*/
  786.      case 0x09: {                /*TAB*/
  787.        actptr++;
  788.        break;
  789.       }
  790.      default  : {
  791.        if ((*actptr>' ') && (*actptr<='~')) return(0);    /*Zeichen gefunden?*/
  792.        else actptr++;
  793.       }
  794.     }
  795.    if (actptr>buffend) return(1);            /*Fileende erreicht?*/
  796.   }
  797. }
  798.  
  799.  
  800. /*Zeiger auf zächste Zeile holen
  801.   Ergebins: 0:Zeile gefunden, actptr=Zeiger auf diese Zeile
  802.         1:File-Ende erreicht
  803. */
  804. GetNextLine()
  805. {
  806.  for(;;) {
  807.    if (*actptr == 0x0A) {
  808.      actptr++;
  809.      linenum++;
  810.      return(0);
  811.     }
  812.    if (actptr>buffend) return(1);            /*Fileende erreicht*/
  813.    actptr++;
  814.   }
  815. }
  816.  
  817.  
  818.  
  819.  
  820. /* gibt Fehlermeldungen des GAL-Assemblers aus
  821.    und gibt Speicher für File-Puffer wieder frei
  822. */
  823. AsmError(errornum)
  824. int    errornum;
  825. {
  826.  FreeMem(fbuff,fsize);
  827.  MyRequest(ERR_REQ,(UBYTE *)"Fehler in der Eingabe-Datei");
  828.  PrintErrorLine(linenum);
  829.  switch (errornum) {
  830.    case  1: {
  831.      PrintText((UBYTE *)"Zeile 1: GAL-Typ erwartet");
  832.      break;
  833.     }
  834.    case  2: {
  835.      PrintText((UBYTE *)"unerwartetes Ende der Eingabe-Datei");
  836.      break;
  837.     }
  838.    case  3: {
  839.      PrintText((UBYTE *)"habe nach '/' Pinnamen erwartet");
  840.      break;
  841.     }
  842.    case  4: {
  843.      PrintText((UBYTE *)"Pinname hat mehr als 8 Buchstaben und Ziffern");
  844.      break;
  845.     }
  846.    case  5: {
  847.      PrintText((UBYTE *)"unerlaubtes Zeichen bei Pin-Definition");
  848.      break;
  849.     }
  850.    case  6: {
  851.      PrintText((UBYTE *)"VCC/GND-Zuweisung nur an den entsprechenden Pins erlaubt");
  852.      break;
  853.     }
  854.    case  7: {
  855.      PrintText((UBYTE *)"für VCC-Pin Zuweisung VCC erwartet");
  856.      break;
  857.     }
  858.    case  8: {
  859.      PrintText((UBYTE *)"für GND-Pin Zuweisung GND erwartet");
  860.      break;
  861.     }
  862.    case  9: {
  863.      PrintText((UBYTE *)"gleicher Pinname kommt mehrfach vor");
  864.      break;
  865.     }
  866.    case 10: {
  867.      PrintText((UBYTE *)"unerlaubte Verwendung von '/'");
  868.      break;
  869.     }
  870.    case 11: {
  871.      PrintText((UBYTE *)"unbekannter Pin-Name in den Boolean-Gleichungen");
  872.      break;
  873.     }
  874.    case 12: {
  875.      PrintText((UBYTE *)"NC (Not Connected) in Boolean-Gleichungen nicht erlaubt");
  876.      break;
  877.     }
  878.    case 13: {
  879.      PrintText((UBYTE *)"nach '.' wird ein 'T', 'E' oder 'R' erwartet");
  880.      break;
  881.     }
  882.    case 14: {
  883.      PrintText((UBYTE *)"'=' wurde erwartet");
  884.      break;
  885.     }
  886.    case 15: {
  887.      PrintText((UBYTE *)"Pin kann nicht als Ausgang programmiert werden");
  888.      break;
  889.     }
  890.    case 16: {
  891.      PrintText((UBYTE *)"gleicher Pin ist mehrfach als Ausgang definiert worden");
  892.      break;
  893.     }
  894.    case 17: {
  895.      PrintText((UBYTE *)"Tristate-Kontrolle: Tristate-Ausgang noch nicht definiert");
  896.      break;
  897.     }
  898.    case 18: {
  899.      PrintText((UBYTE *)"Betriebsmodus 1: Pins 15,16 können nicht als Eingang verwendet werden");
  900.      break;
  901.     }
  902.    case 19: {
  903.      PrintText((UBYTE *)"Betriebsmodus 1: Pins 18,19 können nicht als Eingang verwendet werden");
  904.      break;
  905.     }
  906.    case 20: {
  907.      PrintText((UBYTE *)"Betriebsmodus 2: Pins 12,19 können nicht als Eingang verwendet werden");
  908.      break;
  909.     }
  910.    case 21: {
  911.      PrintText((UBYTE *)"Betriebsmodus 2: Pins 15,22 können nicht als Eingang verwendet werden");
  912.      break;
  913.     }
  914.    case 22: {
  915.      PrintText((UBYTE *)"Tristate-Kontrolle wurde mehrfach angegeben");
  916.      break;
  917.     }
  918.    case 23: {
  919.      PrintText((UBYTE *)"Tristate-Kontrolle wurde auf Registerausgang angewendet");
  920.      break;
  921.     }
  922.    case 24: {
  923.      PrintText((UBYTE *)"Tristate-Kontrolle ohne vorheriges '.T'");
  924.      break;
  925.     }
  926.    case 25: {
  927.      PrintText((UBYTE *)"Ausdrücke VCC und GND nur zur Tristate-Kontrolle erlaubt (x.E = ...)");
  928.      break;
  929.     }
  930.    case 26: {
  931.      PrintText((UBYTE *)"Betriebsmodus 3: Pins 1,11 für 'Clock' und '/OE' reserviert");
  932.      break;
  933.     }
  934.    case 27: {
  935.      PrintText((UBYTE *)"Betriebsmodus 3: Pins 1,13 für 'Clock' und '/OE' reserviert");
  936.      break;
  937.     }
  938.    case 28: {
  939.      PrintText((UBYTE *)"VCC und GND nicht in boolschen Ausdrücken erlaubt");
  940.      break;
  941.     }
  942.    case 29: {
  943.      PrintText((UBYTE *)"bei der Tristate-Kontrolle ist nur EIN Produktterm erlaubt");
  944.      break;
  945.     }
  946.    case 30: {
  947.      PrintText((UBYTE *)"maximal 8 Produktterme erlaubt");
  948.      break;
  949.     }
  950.    case 31: {
  951.      PrintText((UBYTE *)"maximal 7 Produktterme erlaubt");
  952.      break;
  953.     }
  954.    case 32: {
  955.      PrintText((UBYTE *)"vor 'name.E' ist kein '/' erlaubt");
  956.      break;
  957.     }
  958.   }
  959. }
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966. /****************************************************************/
  967. /* ab hier stehen die Routinen, die für der Erstellung der      */
  968. /* Dokumentations-Files zuständig sind                */
  969. /****************************************************************/
  970.  
  971.  
  972. /* erstelle das Chip-File*/
  973. WriteChipFile()
  974. {
  975. UBYTE    filenamebuff[64];
  976. FILE    *fp;
  977. int    n;
  978.  
  979.    if (MyRequest(SAVE_REQ,(UBYTE *)"Bitte Namen für Chip-Datei eingeben")) {
  980.      strcpy(&filenamebuff,&GadgetSBuff);        /*.chp an Dateinamen anfügen*/
  981.      strcat(&filenamebuff,(UBYTE *)".chp");
  982.      if (fp=fopen(&filenamebuff,(UBYTE *)"w")) {
  983.        fprintf(fp,"\n\n");
  984.        WriteSpaces(fp,32);
  985.        if (gal_type == GAL16V8)    fprintf(fp,"GAL16V8\n\n");
  986.        else fprintf(fp,"GAL20V8\n\n");
  987.        WriteSpaces(fp,26);
  988.        fprintf(fp,"-------\\___/-------\n");
  989.  
  990.        for (n=0; n<num_of_pins/2; n++) {
  991.      WriteSpaces(fp,25-strlen(&PinNames[n][0]));
  992.      fprintf(fp,"%s | %2d           %2d | %s\n",&PinNames[n][0],n+1,num_of_pins-n,&PinNames[num_of_pins-n-1][0]);
  993.      if (n<num_of_pins/2-1) {
  994.        WriteSpaces(fp,26);
  995.        fprintf(fp,"|                 |\n");
  996.       }
  997.     }
  998.  
  999.        WriteSpaces(fp,26);
  1000.        fprintf(fp,"-------------------\n");
  1001.  
  1002.        if (fclose(fp)==EOF) ErrorReq(8);        /*Datei läßt sich nicht schließem*/
  1003.       }
  1004.     }
  1005. }
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011. /* erstelle das Pin-File*/
  1012. WritePinFile()
  1013. {
  1014. UBYTE    filenamebuff[64];
  1015. FILE    *fp;
  1016. int    k, n, flag;
  1017.  
  1018.    if (MyRequest(SAVE_REQ,(UBYTE *)"Bitte Namen für Pin-Datei eingeben")) {
  1019.      strcpy(&filenamebuff,&GadgetSBuff);        /*.pin an Dateinamen anfügen*/
  1020.      strcat(&filenamebuff,(UBYTE *)".pin");
  1021.      if (fp=fopen(&filenamebuff,(UBYTE *)"w")) {
  1022.        fprintf(fp,"\n\n");
  1023.        fprintf(fp," Pin # | Name     | Pin Type\n");
  1024.        fprintf(fp,"-----------------------------\n");
  1025.  
  1026.        for (n=1; n<=num_of_pins; n++) {
  1027.      fprintf(fp,"  %2d   | ",n);
  1028.      fprintf(fp,"%s",PinNames[n-1]);
  1029.      WriteSpaces(fp,9-strlen(PinNames[n-1]));
  1030.  
  1031.      flag = 0;
  1032.      if (n == num_of_pins/2) {
  1033.        fprintf(fp,"| GND\n");
  1034.        flag = 1;
  1035.       }
  1036.      if (n == num_of_pins) {
  1037.        fprintf(fp,"| VCC\n\n");
  1038.        flag = 1;
  1039.       }
  1040.      if ((modus == MODE3) && (n == 1)) {
  1041.        fprintf(fp,"| Clock\n");
  1042.        flag = 1;
  1043.       }
  1044.      if (modus == MODE3) {
  1045.        if ((gal_type == GAL16V8) && (n == 11)) {
  1046.          fprintf(fp,"| /OE\n");
  1047.          flag = 1;
  1048.         }
  1049.        if ((gal_type == GAL20V8) && (n == 13)) {
  1050.          fprintf(fp,"| /OE\n");
  1051.          flag = 1;
  1052.         }
  1053.       }
  1054.                             /*OLMC-Pin?*/
  1055.      if ( ((gal_type == GAL16V8) && (n >= 12) && (n <= 19)) ||
  1056.           ((gal_type == GAL20V8) && (n >= 15) && (n <= 22)) ) {
  1057.        if (gal_type == GAL16V8)
  1058.          k = n-12;
  1059.        else
  1060.          k = n-15;
  1061.        if (OLMC[k].PinType != INPUT)
  1062.          if (OLMC[k].PinType)
  1063.            fprintf(fp,"| Output\n");
  1064.          else
  1065.            fprintf(fp,"| NC\n");
  1066.        else
  1067.          fprintf(fp,"| Input\n");
  1068.       }
  1069.      else {
  1070.        if (!flag) 
  1071.          fprintf(fp,"| Input\n");
  1072.       }
  1073.     }
  1074.        if (fclose(fp)==EOF) ErrorReq(8);        /*Datei läßt sich nicht schließem*/
  1075.       }
  1076.     }
  1077. }
  1078.  
  1079.  
  1080.  
  1081. /* erstelle das Fuse-File*/
  1082. WriteFuseFile()
  1083. {
  1084. UBYTE    filenamebuff[64];
  1085. FILE    *fp;
  1086. int    n,   row, col, pin;
  1087. int    xor, ac1;
  1088.  
  1089.    if (MyRequest(SAVE_REQ,(UBYTE *)"Bitte Namen für Fuse-Datei eingeben")) {
  1090.      strcpy(&filenamebuff,&GadgetSBuff);        /*.fus an Dateinamen anfügen*/
  1091.      strcat(&filenamebuff,(UBYTE *)".fus");
  1092.      if (fp=fopen(&filenamebuff,(UBYTE *)"w")) {
  1093.        if (gal_type == GAL16V8)
  1094.      pin = 19;
  1095.        else
  1096.      pin = 22;
  1097.        for (row=0; row<ROW_SIZE; row++) {
  1098.      if (!((row) % 8)) {
  1099.        fprintf(fp,"\n\nPin %2d = ",pin);
  1100.        fprintf(fp,"%s",PinNames[pin-1]);
  1101.        WriteSpaces(fp,13-strlen(PinNames[pin-1]));
  1102.        if (gal_type == GAL16V8) {
  1103.          xor = Jedec.GALXOR[19-pin];
  1104.          ac1 = Jedec.GALAC1[19-pin];
  1105.         }
  1106.        else {
  1107.          xor = Jedec.GALXOR[22-pin];
  1108.          ac1 = Jedec.GALAC1[22-pin];
  1109.         }
  1110.        fprintf(fp,"XOR = %1d   AC1 = %1d",xor,ac1);
  1111.        pin--;    
  1112.       }
  1113.      fprintf(fp,"\n%2d ",row);
  1114.      for (col=0; col<num_of_col; col++) {
  1115.        if (!( (col) % 4) )
  1116.          fprintf(fp," ");
  1117.        if (Jedec.GALLogic[row * num_of_col + col])
  1118.          fprintf(fp,"-");
  1119.        else
  1120.          fprintf(fp,"x");
  1121.       }
  1122.     }
  1123.        fprintf(fp,"\n\n");
  1124.        if (fclose(fp)==EOF) ErrorReq(8);        /*Datei läßt sich nicht schließem*/
  1125.       }
  1126.     }
  1127. }
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133. /* schreibt Anzahl "numof" Spaces in File "fp"*/
  1134. WriteSpaces(fp, numof)
  1135. FILE    *fp;
  1136. int    numof;
  1137. {
  1138. int n;
  1139.  
  1140.  for (n=0; n<numof; n++)
  1141.    fprintf(fp," ");
  1142. }
  1143.  
  1144.